package com.gaofans.nrpc.common.protocol;

import com.gaofans.nrpc.common.processor.Builder;

import java.util.Objects;

/**
 * @author GaoFans
 */
public class RpcRequestBuilder implements Builder<RpcRequest> {

    private RpcRequest request;

    public RpcRequestBuilder() {
        this.request = new RpcRequest();
    }

    public RpcRequestBuilder id(long id){
        this.request.setSequenceId(id);
        return this;
    }

    public RpcRequestBuilder className(String className){
        this.request.setClassName(className);
        return this;
    }

    public RpcRequestBuilder methodName(String methodName){
        this.request.setMethodName(methodName);
        return this;
    }

    public RpcRequestBuilder typeParameters(Class<?>[] typeParameters){
        this.request.setTypeParameters(typeParameters);
        return this;
    }

    public RpcRequestBuilder parametersVal(Object[] parametersVal){
        this.request.setParametersVal(parametersVal);
        return this;
    }


    @Override
    public RpcRequest build() {
        Objects.requireNonNull(this.request.getClassName());
        Objects.requireNonNull(this.request.getMethodName());
        Objects.requireNonNull(this.request.getParametersVal());
        Objects.requireNonNull(this.request.getTypeParameters());
        return Objects.requireNonNull(request);
    }

}
